home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Bus / A / Acius08⁄92.cpt / Acius08_92 / Encoding_Decipheringƒ / Sources / DecryptPicture.a next >
Text File  |  1992-08-17  |  3KB  |  109 lines

  1. ;
  2. ; Deciphering pictures external routine for 4D
  3. ; written by François Marchal, © ACI 1992
  4. ; Parameters :
  5. ; -> Picture to encode
  6. ; -> Longint key word (you need the same key to encode and to decipher the picture)
  7. ;
  8.  
  9.     CASE    OBJ
  10.     INCLUDE 'traps.a'
  11.     
  12. picsize            EQU        104
  13. signature        EQU        98    
  14. masignature        EQU        $464D
  15. Cle                EQU        100
  16. picend            EQU        6
  17.  
  18.     EXPORT        DecryptPicture
  19.  
  20. DecryptPicture        PROC         
  21.     CODE
  22.  
  23.     LINK        A6,#$0
  24.     MOVEM.L        D4-D7/A4,-(A7)            ; save the used registers
  25.     MOVEA.L        12(A6),A4
  26.     MOVE.L        (A4),A4                    ; A4 : Handle on the picture to encode
  27.     BEQ            Fini                    ; if the Handle passed is Nil, don't do anything
  28.  
  29.     MOVE.L        (A4),A0    
  30.     MOVE.W        signature(A0),D0
  31.     CMPI.W        #masignature,D0            ; verify if the handle hasn't been signed
  32.     BNE.S        fini                    ; if the picture has already been encoded, don't do anything
  33.     
  34.     MOVE.L        8(A6),A0                ; dereferencing (parameter passed in var)
  35.     MOVE.L        (A0),D4                    ; of the deciphering key
  36.     MOVE.L        (A4),A0                    ; dereferencing the Handle
  37.     CMP.L        Cle(A0),D4                ; compare the deciphering key passed with the encoding key
  38.     BNE.S        fini                    ; don't do anything if the keys are not identical
  39.  
  40.     MOVE.L        A4,A0
  41.     _GetHandleSize
  42.     MOVE.L        D0,D7                    ; memorize the size of the new Handle in D7
  43.     BEQ.S        fini                    ; if the Handle is empty, stop
  44.  
  45.     SUB.L        #picsize+picend,D7        ; D7 = size of the handle minus the header minus the picend
  46.     BLE.S        fini                    ; if it's negative, stop
  47.  
  48.     MOVE.L        (A4),A0                    ; go to the beginning of the data
  49.     ADDA.L        #picsize,A0                ; plus the header
  50.  
  51.     MOVE.L        D7,D0                    ; D0 : number of bytes to decipher
  52.  
  53.     MOVE.L        D0,D6
  54.     ANDI.L        #$1F,D6                    ; D6 -> the remainder of the whole division of D7 by 32
  55.  
  56.     LSR.L        #5,D0                    ; divide by 32 of the size of the Handle
  57.     BEQ.S        GereReste                ; allows us to know the number of passes in the loop
  58.  
  59.     SUBQ        #1,D0                    ; take 1 to D7 for the dbra
  60.  
  61. Loop:
  62.     MOVE.L        D4,D5
  63.     SUB.L        D0,D5
  64.     EOR.L        D5,(A0)+                ; 1
  65.     EOR.L        D5,(A0)+                ; 2
  66.     EOR.L        D5,(A0)+                ; 3
  67.     EOR.L        D5,(A0)+                ; 4
  68.     EOR.L        D5,(A0)+                ; 5
  69.     EOR.L        D5,(A0)+                ; 6
  70.     EOR.L        D5,(A0)+                ; 7
  71.     EOR.L        D5,(A0)+                ; 8 x 4 = 32 bytes processed by the loop
  72.     DBRA        D0,Loop                    
  73.  
  74. GereReste:                                ; take care of the remaining bytes
  75.     CMPI.L        #0,D6
  76.     BLE.S        Suite
  77.     EOR.B        D6,(A0)+
  78.     SUBQ        #1,D6
  79.     BRA.S        GereReste
  80.  
  81. Suite:
  82.     MOVEA.L        (A4),A1                    ; A0 = Source -> Block address + block size - header size
  83.     MOVEA.L        A1,A0                    ; A1 = Dest   -> Block address
  84.     ADDA.L        D7,A0                    ; of the data moved toward the bottom of the size of the lock picture
  85.     MOVE.L        #picsize,D0                ; Length -> la taille primary of the Handle
  86.     _BlockMove                            ; replace the primary header on top of mine
  87.  
  88.     MOVE.L        (A4),A0
  89.     ADDA.L        D7,A0                    ; move the 6 bytes from the picend 
  90.     MOVEA.L        A0,A1                    ; to the end of the block
  91.     ADDA.L        #picsize,A1
  92.     MOVE.L        (A1)+,(A0)+
  93.     MOVE.W        (A1)+,(A0)    
  94.  
  95.     MOVE.L        A4,A0                    ; Handle in A0
  96.     MOVE.L        D7,D0                    ; new size in D0    
  97.     ADDQ        #picend,D0
  98.     _SetHandleSize                        ; readjust the size of the Handle (delet the header)
  99.     
  100. Fini:    
  101.     MOVEM.L        (A7)+,D4-D7/A4            ; restoring the registers
  102.     UNLK        A6
  103.     MOVEA.L        (A7)+,A0                ; read the return address
  104.     ADDQ.L        #$8,A7                    ; take the parameters off of the stack
  105.     JMP            (A0)                    ; and return to the calling point
  106.  
  107.     ENDP    
  108.     END